Sprocket Menus 3
Volume Number: 11
Issue Number: 7
Column Tag: Getting Started
Sprocket Menus, Part 3 
By Dave Mark, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Last month, we added a new class to our Drag Manager friendly picture window
program. In addition to the Drag Manager friendly text window, we also added a pair of
menus to the program. The Text menu appeared when the frontmost window was a text window, and the Picture window appeared when the frontmost window was a picture window.
We learned about static data members and member functions, and added the data
member fgMenu to both the TTextWindow and TPictureWindow classes. fgMenu
static member function named SetUpStaticMenu() to both classes.
SetUpStaticMenu() registers the commands associated with its classes’ menu (go
back a few columns if you don’t know about menu commands and CMNU resources).
Since fgMenu is static, it is global to the class, and not to a specific object. That means
we don’t need to create a new Text menu for each TTextWindow object we create. By having a single menu per class, we can register the menu commands at initialization,
then leave the commands registered as we delete the menu from the menu bar and
reinsert it, depending on the type of the frontmost window.